function setTitle(title) {
  if (!title) return

  // const isiOS = !!window.navigator.userAgent
  //   .match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)

  document.title = title

  // if (isiOS) {
  //   setWebViewTitle(title)
  // }
}

let setedTitle = false

/**
 * 动态设置标题
 * @param  {[Boolean]} cancel [如果view模块被当作组件使用时候则不设置title]
 * @modifiers  {[Boolean]} async 异步设置标题 Usage: v-title.async
 *
 * Usage
 * v-title.async="{ value: 'title', cancel: true }"
 */
export default {
  bind(el, binding) {
    const { value } = binding
    const hasCancelProperty = {}.hasOwnProperty.call(value, 'cancel')
    if (hasCancelProperty) return

    setTitle(value.value)
  },

  update(el, binding) {
    const { modifiers, value } = binding
    const hasCancelProperty = {}.hasOwnProperty.call(value, 'cancel')
    if (hasCancelProperty) return

    if (modifiers.async && value && !setedTitle) {
      setTitle(value.value)
      setedTitle = true
    }
  },
}

